package com.ethan.http;

import android.text.TextUtils;

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * token拦截器
 */
public class TokenHeaderInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        //可以自动添加登录后的token 从本地缓存去取即可
        String token = "123_123";
        if (TextUtils.isEmpty(token))
        {
            Request request = chain.request();
            return chain.proceed(request);
        }else{

            Request request = chain.request();
            Request newRequest = request.newBuilder().header("token",token).build();
            return chain.proceed(newRequest);
        }
    }
}
